<?php

namespace App\Http\Controllers\Recommend;

use App\Http\Controllers\Controller;
use App\Http\Requests\Recommend\ApppageRectplAreaRequest;
use App\Models\Application\Apppage;
use App\Models\Application\Muticolumn;
use App\Models\Application\Pagetpl;
use App\Models\Application\Paneltpl;
use App\Models\Entity\Asset\Video\Vasseti;
use App\Models\Entity\Asset\Video\Vseriali;
use App\Models\Entity\Column\Collist;
use App\Models\Entity\Column\ColumnType;
use App\Models\Entity\Column\Data;
use App\Models\Recommend\Reclist0;
use App\Models\Recommend\Reclist0Data;
use App\Models\Recommend\ApppageRectpl;
use App\Models\Recommend\ApppageRectplArea;
use App\Models\Recommend\ApppageRectplData;
use App\Repositories\Recommend\ApppageRectplAreaRepository;
use DB;
use Encore\Admin\Controllers\ModelForm;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Flash;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Storage;
use Response;

class ApppageRectplAreaController extends Controller
{
    use ModelForm;

    /** @var  ApppageRectplAreaRepository */
    private $apppageRectplAreaRepository;

    public function __construct(ApppageRectplAreaRepository $apppageRectplAreaRepo)
    {
        $this->apppageRectplAreaRepository = $apppageRectplAreaRepo;
    }

    /**
     * Display a listing of the ApppageRectplArea.
     *
     * @return Response
     */
    public function index(Request $request)
    {
        $apppageRectplId = $request->input('apppage_rectpl_id');
        $pagetplId       = $request->input('pagetpl_id');
        $paneltplId      = $request->input('paneltpl_id');
        if (!empty($apppageRectplId) && !empty($pagetplId) && !empty($paneltplId)) {
            $apppageRectpl = ApppageRectpl::find($apppageRectplId);

            if (empty($apppageRectpl)) {
                Flash::error(__('application.apppage_rectpls.not_found'));
                return redirect(route('application.apppage_rectpls.index'));
            }
            // 获取栏目推荐区位信息定义
            $apppageRectplAreas = ApppageRectplArea::where(['apppage_rectpl_id' => $apppageRectplId, 'pagetpl_id' => $pagetplId, 'paneltpl_id' => $paneltplId])->get();
            if (empty($apppageRectplAreas->first())) {
                // 获取panel模板信息
                $paneltpl       = Paneltpl::where(['id' => $paneltplId])->first();
                $panelAreaDatas = [];
                $areas          = json_decode($paneltpl->areas, true);
                if (!empty($areas)) {
                    foreach ($areas as $key => $area) {
                        $panelAreaDatas[$key]['apppage_rectpl_id'] = intval($apppageRectplId);
                        $panelAreaDatas[$key]['pagetpl_id']        = intval($pagetplId);
                        $panelAreaDatas[$key]['paneltpl_id']       = intval($paneltplId);
                        $panelAreaDatas[$key]['area']              = $area;
                        $panelAreaDatas[$key]['data']              = null;
                        $panelAreaDatas[$key]['created_at']        = date('Y-m-d H:i:s', time());
                    }
                }
                $result = DB::table('apppage_rectpl_areas')->insert($panelAreaDatas);
                if (empty($result)) {
                    Flash::error(__('application.apppage_rectpls.not_found'));

                    return redirect(route('application.apppage_rectpls.index'));
                }
            }
        }
        return Admin::content(function (Content $content) use ($request) {

            $content->header(__('recommend.apppage_rectpl_areas.index_header'));
            $content->description(__('recommend.apppage_rectpl_areas.index_description'));

            $content->body($this->grid($request));
            $content->row(view('recommend.apppage-rectpl-areas.index'));
        });
    }

    /**
     * Show the form for creating a new ApppageRectplArea.
     *
     * @return Response
     */
    public function create()
    {
        return Admin::content(function (Content $content) {

            $content->header(__('recommend.apppage_rectpl_areas.create_header'));
            $content->description(__('recommend.apppage_rectpl_areas.create_description'));

            $content->body($this->form());

        });
    }

    /**
     * Store a newly created ApppageRectplArea in storage.
     *
     * @param ApppageRectplAreaRequest $request
     *
     * @return Response
     */
    public function store(ApppageRectplAreaRequest $request)
    {
        $input = $request->all();

        $apppageRectplArea = $this->apppageRectplAreaRepository->create($input);

        Flash::success(__('recommend.apppage_rectpl_areas.saved_success'));

        return Input::get('_previous_') ? redirect(Input::get('_previous_')) : redirect(route('recommend.apppage_rectpl_areas.index'));

    }

    /**
     * Display the specified ApppageRectplArea.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        $apppageRectplArea = $this->apppageRectplAreaRepository->findWithoutFail($id);

        if (empty($apppageRectplArea)) {
            Flash::error(__('recommend.apppage_rectpl_areas.not_found'));

            return redirect(route('recommend.apppage_rectpl_areas.index'));
        }

        return view('recommend.apppage_rectpl_areas.show')->with('apppageRectplArea', $apppageRectplArea);

    }

    /**
     * Show the form for editing the specified ApppageRectplArea.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function edit($id)
    {

        return Admin::content(function (Content $content) use ($id) {

            $content->header(__('recommend.apppage_rectpl_areas.edit_header'));
            $content->description(__('recommend.apppage_rectpl_areas.edit_description'));

            $content->body($this->form()->edit($id));

        });
    }

    /**
     * Update the specified ApppageRectplArea in storage.
     *
     * @param  int              $id
     * @param ApppageRectplAreaRequest $request
     *
     * @return Response
     */
    public function update($id, ApppageRectplAreaRequest $request)
    {
        $apppageRectplArea = $this->apppageRectplAreaRepository->findWithoutFail($id);

        if (empty($apppageRectplArea)) {
            Flash::error(__('recommend.apppage_rectpl_areas.not_found'));

            return redirect(route('recommend.apppage_rectpl_areas.index'));
        }
        $input = $request->all();

        $apppageRectplArea = $this->apppageRectplAreaRepository->update($input, $id);

        Flash::success(__('recommend.apppage_rectpl_areas.updated_success'));

        return Input::get('_previous_') ? redirect(Input::get('_previous_')) : redirect(route('recommend.apppage_rectpl_areas.index'));
    }

    /**
     * Remove the specified ApppageRectplArea from storage.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        // 根据 `,` 判断传递过来的是单个id还是多个id
        if (substr_count($id, ',') >= 1) {
            $id = explode(",", $id);
        }

        // 如果是数组则进行批量删除
        if (is_array($id)) {
            if ($flag = $this->apppageRectplAreaRepository->batchDelete('id', $id)) {

                return response()->json(['message' => __('recommend.apppage_rectpl_areas.deleted_success'), 'status' => $flag]);
            } else {
                return response()->json(['message' => __('base.deleted.error'), 'status' => $flag]);
            }
        }

        $apppageRectplArea = $this->apppageRectplAreaRepository->findWithoutFail($id);

        if (empty($apppageRectplArea)) {
            Flash::error(__('recommend.apppage_rectpl_areas.not_found'));

            return redirect(route('recommend.apppage_rectpl_areas.index'));
        }

        if ($flag = $this->apppageRectplAreaRepository->delete($id)) {

            return response()->json(['message' => __('recommend.apppage_rectpl_areas.deleted_success'), 'status' => $flag]);
        } else {
            return response()->json(['message' => __('base.deleted.error'), 'status' => $flag]);
        }
    }

    /**
     * [form description]
     * @return {[type]} [description]
     */
    protected function form()
    {
        return Admin::form(ApppageRectplArea::class, function (Form $form) {

            $form->display('id', 'ID');
            $apppageRectpls = ApppageRectpl::pluck('title', 'id');
            $form->select('apppage_rectpl_id', '推荐位定义')->options($apppageRectpls);
            // $pagetpls = Pagetpl::pluck('title', 'id');
            // $form->select('pagetpl_id', '页面模板')->options($pagetpls);
            $form->hidden('pagetpl_id', '页面模板');
            $paneltpls = Paneltpl::pluck('title', 'id');
            $form->select('paneltpl_id', '模板编号')->options($paneltpls);
            $form->text('area', '区位编号');
            $form->textarea('onclick', 'onclick事件');
            $form->textarea('data', '推荐数据');

            $form->display('created_at', __('base.created_at'));
            $form->display('updated_at', __('base.updated_at'));

        });
    }

    /**
     * [grid description]
     * @return {[type]} [description]
     */
    protected function grid(Request $request)
    {

        return Admin::grid(ApppageRectplArea::class, function (Grid $grid) use ($request) {
            $apppageRectplId = $request->input('apppage_rectpl_id');
            $pagetplId       = $request->input('pagetpl_id');
            $paneltplId      = $request->input('paneltpl_id');
            if (!empty($apppageRectplId) && !empty($pagetplId) && !empty($paneltplId)) {
                $grid->model()->where(['apppage_rectpl_id' => $apppageRectplId, 'pagetpl_id' => $pagetplId, 'paneltpl_id' => $paneltplId]);
            } else {
                $grid->model();
            }

            // 添加按钮
            // if (Admin::user()->cannot('recommend.apppage_rectpl_areas.create')) {
            $grid->disableCreation();
            // }

            // 编辑和删除按钮
            $grid->actions(function ($actions) {
                $id          = $actions->getKey();
                $pagetpl_id  = $actions->row->pagetpl_id;
                $paneltpl_id = $actions->row->paneltpl_id;
                $apppage_rectpl_id = $actions->row->apppage_rectpl_id;
                $area        = $actions->row->area;
                // 编辑按钮
                if (Admin::user()->cannot('recommend.apppage_rectpl_areas.edit')) {
                    $actions->disableEdit();
                }
                // 删除按钮
                if (Admin::user()->cannot('recommend.apppage_rectpl_areas.destroy')) {
                    $actions->disableDelete();
                }

                // 添加推荐位定义区位数据
                $url = route('recommend.apppage_rectpl_areas.add_rectpl_data', ['apppage_rectpl_area_id' => $id]);
                $actions->append('<a href="' . $url . '" data-toggle="modal"  data-target="#add-apppage-rectpl-area-modal" title="添加数据">&nbsp;&nbsp;添加数据/&nbsp;&nbsp;</a>');
                $url = route('recommend.apppage_rectpl_datas.index', ['apppage_rectpl_area_id'=>$id,'pagetpl_id' => $pagetpl_id, 'paneltpl_id' => $paneltpl_id, 'area' => $area]);
                $actions->append('<a href="' . $url . '"  title="编辑数据">编辑数据/&nbsp;&nbsp;</a>');
            });

            // 导出按钮
            if (Admin::user()->cannot('recommend.apppage_rectpl_areas.export')) {
                $grid->disableExport();
            }

            // 批量操作
            $grid->tools(function ($tools) {
                $tools->append('<a href="javascript:void(0)" onclick="history.go(-1)" class="btn btn-default btn-sm" style="margin-right: 0px"> <i class="fa fa-arrow-left"></i>返回</a>');

                $tools->batch(function ($batch) {
                    // 批量删除按钮
                    if (Admin::user()->cannot('recommend.apppage_rectpl_areas.batch_destroy')) {
                        $batch->disableDelete();
                    }
                });
            });

            $grid->column('id', 'ID')->sortable();
            $grid->column('apppageRectpl.title', '推荐位定义')->sortable();
            // $grid->column('pagetpl.title', '页面模板')->sortable();
            $grid->column('paneltpl.title', '模板编号')->sortable();
            $grid->column('area', '区位编号')->sortable();
            $grid->column('onclick', 'onclick事件')->sortable();
            // $grid->column('data', '推荐数据')->sortable();
            // $grid->column('推荐数据')->display(function () {
            //     $count = ApppageRectplData::where(['pagetpl_id' => $this->pagetpl_id, 'paneltpl_id' => $this->paneltpl_id, 'area' => $this->area])->count();
            //     $url = route('recommend.apppage_rectpl_datas.index', ['pagetpl_id'=>$this->pagetpl_id,'paneltpl_id' => $this->paneltpl_id,'area' => $this->area]);
            //     $data = "<a target='' href=" . $url . ">" . $count . "条数据</a>"; // _blank
            //     return $data;
            // });

            /**
             * 过滤处理
             */
            $grid->filter(function ($filter) {
                // 页面
                $tmpPagetpls = Paneltpl::pluck('title', 'id');
                $filter->equal('paneltpl_id', '页面')->select($tmpPagetpls);
                // // 禁用id查询框
                // $filter->disableIdFilter();
                $filter->like('area', '区位编号');

            });
        });
    }

    /**
     * 加载推荐模板数据
     * @param Request $request [description]
     */
    public function addpageRectplDatas(Request $request)
    {
        $apppageRectplAreaId = $request->input('apppage_rectpl_area_id');
        $apppageRectplArea   = $this->apppageRectplAreaRepository->findWithoutFail($apppageRectplAreaId);

        if (empty($apppageRectplArea)) {
            Flash::error(__('recommend.apppage_rectpl_areas.not_found'));

            return redirect(route('recommend.apppage_rectpl_areas.index'));
        }
        $datas = [];
        // $data                            = Data::get(['title', 'id'])->toArray();
        $tmpColumnTypes = ColumnType::get(['tags', 'id', 'title', 'pid'])->toArray();
        $tempArr        = [];
        foreach ($tmpColumnTypes as $key => $columnType) {
            $tags = explode(',', $columnType['tags']);
            foreach ($tags as $tag) {
                if (in_array($tag, ['any', 'page_rectpl'])) {
                    $tempArr[] = $columnType['id'];
                }
            }
        }
        $data                            = ColumnType::whereIn('id', $tempArr)->get(['title', 'id'])->toArray();
        $datas['datas']                  = $data;
        $datas['apppage_rectpl_area_id'] = $apppageRectplAreaId;
        return view('recommend.apppage-rectpl-areas.create', $datas);
    }

    /**
     * 根据数据类型获取数据
     * @param  Request $request [description]
     * @return [type]           [description]
     */
    public function getDataByDataType(Request $request)
    {
        // 搜索框的值
        $search_value = $request->input('search_value');
        // 获取数据类型
        $dataType = $request->input('data_type');
        // 获取栏目推荐区位ID
        $apppageRectplAreaId = $request->input('apppage_rectpl_area_id');
        $apppageRectplArea   = ApppageRectplArea::with(['pagetpl', 'paneltpl'])->where(['id' => $apppageRectplAreaId])->first();
        if (empty($apppageRectplArea)) {
            return response()->json(['content' => '无此页面推荐区位', 'status' => false]);
        }
        // 获取此类型的数据ID
        // $data = Data::where(['id' => $dataType])->first();
        $data = ColumnType::where(['id' => $dataType])->first();
        if (empty($data)) {
            return response()->json(['content' => '无此栏目类型', 'status' => false]);
        }
        $pageRectpldataIds = [];
        // 当前栏目区位数据
        $relation   = [];
        $whereData  = [];
        $pageId     = $apppageRectplArea->pagetpl_id;
        $paneltplId = $apppageRectplArea->paneltpl_id;
        $area       = $apppageRectplArea->area;
        // 获取页面推荐区位已有的数据
        $pageRectpldataIds = ApppageRectplData::where(['apppage_rectpl_area_id' => $apppageRectplAreaId, 'pagetpl_id' => $pageId, 'paneltpl_id' => $paneltplId, 'area' => $area, 'data_id' => $dataType])->pluck('resource_data_id')->toArray();
        $model = '';
        switch ($data->name) {
            case 'collist':
                $model = new Collist();
                break;
            case 'column':
                $model = new Muticolumn();
                break;
            case 'vodpkg':
                $model    = new Vasseti();
                $relation = ['vcat', 'actors', 'directors', 'vareas', 'vlangs', 'vyears', 'vcattags'];
                break;
            case 'livepkg':
                $model    = new Vasseti();
                $relation = ['vcat', 'actors', 'directors', 'vareas', 'vlangs', 'vyears', 'vcattags'];
                break;
            case 'vasset':
                $model    = new Vasseti();
                $relation = ['vcat', 'actors', 'directors', 'vareas', 'vlangs', 'vyears', 'vcattags'];
                break;
            case 'panellist':
                $model = new ApppageRectpl();
                break;
            case 'reclist0':
                $model = new Reclist0();
                break;
            case 'assetpkg':
                $model    = new Vasseti();
                $relation = ['vcat', 'actors', 'directors', 'vareas', 'vlangs', 'vyears', 'vcattags'];
                break;
            case 'aasset':
                $model    = new Vasseti();
                $relation = ['vcat', 'actors', 'directors', 'vareas', 'vlangs', 'vyears', 'vcattags'];
                break;
            case 'iasset':
                $model    = new Vasseti();
                $relation = ['vcat', 'actors', 'directors', 'vareas', 'vlangs', 'vyears', 'vcattags'];
                break;
            case 'column_fun':
                $model = new ColumnFun();
                break;
            case 'SPDJ':
                $model     = new Vasseti();
                $whereData = ['serials' => 1];
                $relation  = ['vcat', 'actors', 'directors', 'vareas', 'vlangs', 'vyears', 'vcattags'];
                break;
            case 'SPFJ':
                $model    = new Vasseti();
                $relation = ['vcat', 'actors', 'directors', 'vareas', 'vlangs', 'vyears', 'vcattags'];
                break;
            default:
                // $model    = new Vasseti();
                // $relation = ['vcat', 'actors', 'directors', 'vareas', 'vlangs', 'vyears', 'vcattags'];
                break;
        }

        $data         = [];
        $data['draw'] = $request->get('draw');
        $start        = $request->get('start') ?: 0;
        $length       = $request->get('length') ?: 10;
        $order        = $request->get('order');
        $columns      = $request->get('columns');
        $search       = $request->get('search');
        if ($order) {
            $orderColumData = $columns[$order[0]['column']]['data'];
        }

        // 排序字段
        $ord = '';
        if (!empty($orderColumData)) {
            $ord = $orderColumData . ' ' . $order[0]['dir'];
        } else {
            $ord = 'id asc';
        }
        if (empty($model)) {
            $data['recordsTotal']    = 0;
            $data['recordsFiltered'] = 0;
            $data['data']            = [];
        } else {

            // 获取类名称
            $model                   = (new \ReflectionClass($model))->getName();
            $data['recordsTotal']    = $model::where($whereData)->whereNotIn('id', $pageRectpldataIds)->count();
            $data['recordsFiltered'] = $model::where($whereData)->whereNotIn('id', $pageRectpldataIds)->count();
            $data['data']            = $model::with($relation)
                ->whereNotIn('id', $pageRectpldataIds)
                ->where($whereData)
                ->skip($start)->take($length)
                ->orderByRaw($ord)
                ->get();
        }
        return response()->json($data);
    }

    /**
     * 推荐数据包
     * @param  tag_contentRequest $request [description]
     * @return [type]                      [description]
     */
    public function pageRectplAreaDataStore(Request $request)
    {
        // 获取传递过来是哪个栏目推荐
        $apppageRectplAreaId = $request->input('apppage_rectpl_area_id');
        if (empty($apppageRectplAreaId)) {
            return response()->json(['content' => '推荐位ID不能为空', 'status' => false]);
        }
        $apppageRectplArea = ApppageRectplArea::with(['pagetpl', 'paneltpl'])->where(['id' => $apppageRectplAreaId])->first();
        if (empty($apppageRectplArea)) {
            return response()->json(['content' => '无此页面推荐区位', 'status' => false]);
        }
        // 获取数据类型
        $dataType = $request->input('data_type');
        if (empty($dataType)) {
            return response()->json(['content' => '数据类型ID不能为空', 'status' => false]);
        }
        // 获取所有传递来的数据ID
        $dataIds = $request->input('data_id');
        if (!is_array($dataIds)) {
            return response()->json(['content' => '数据为空,请选择数据', 'status' => false]);
        }

        $data = ColumnType::where(['id' => $dataType])->first();
        if (empty($data)) {
            return response()->json(['content' => '无此栏目类型', 'status' => false]);
        }
        switch ($data->name) {
            case 'collist':
                $model = new Collist();
                break;
            case 'column':
                $model = new Muticolumn();
                break;
            case 'vodpkg':
                $model    = new Vasseti();
                $relation = ['vcat', 'actors', 'directors', 'vareas', 'vlangs', 'vyears', 'vcattags'];
                break;
            case 'livepkg':
                $model    = new Vasseti();
                $relation = ['vcat', 'actors', 'directors', 'vareas', 'vlangs', 'vyears', 'vcattags'];
                break;
            case 'panellist':
                $model = new ApppageRectpl();
                break;
            case 'reclist0':
                $model = new Reclist0();
                break;
                break;
            case 'vasset':
                $model    = new Vasseti();
                $relation = ['vcat', 'actors', 'directors', 'vareas', 'vlangs', 'vyears', 'vcattags'];
                break;
            case 'aasset':
                $model    = new Vasseti();
                $relation = ['vcat', 'actors', 'directors', 'vareas', 'vlangs', 'vyears', 'vcattags'];
                break;
            case 'iasset':
                $model    = new Vasseti();
                $relation = ['vcat', 'actors', 'directors', 'vareas', 'vlangs', 'vyears', 'vcattags'];
                break;
            case 'assetpkg':
                $model    = new Vasseti();
                $relation = ['vcat', 'actors', 'directors', 'vareas', 'vlangs', 'vyears', 'vcattags'];
                break;
            case 'SPDJ':
                $model     = new Vasseti();
                $whereData = ['serials' => 1];
                $relation  = ['vcat', 'actors', 'directors', 'vareas', 'vlangs', 'vyears', 'vcattags'];
                break;
            case 'SPFJ':
                $model = new Vasseti();
                // $relation = ['vcat', 'actors', 'directors', 'vareas', 'vlangs', 'vyears', 'vcattags'];
                break;
            default:
                // $model    = new Vasseti();
                // $relation = ['vcat', 'actors', 'directors', 'vareas', 'vlangs', 'vyears', 'vcattags'];
                break;
        }
        // 获取名称名称
        $model          = (new \ReflectionClass($model))->getName();
        $pageId         = $apppageRectplArea->pagetpl_id;
        $paneltplId     = $apppageRectplArea->paneltpl_id;
        $area           = $apppageRectplArea->area;
        $panelAreaDatas = [];
        // 开启事务
        DB::beginTransaction();
        try {
            // 循环所有的数据
            foreach ($dataIds as $key => $dataid) {
                // 判断栏目区位是否已存在此数据
                if ($this->isExistAppAreaData($pageId, $paneltplId, $area, $dataType, $dataid)) {
                    $resoureData = $model::where(['id' => $dataid])->first();

                    if (!empty($resoureData)) {
                        // 不存在的话根据数据类型获取数据
                        $panelAreaDatas[$key]['apppage_rectpl_area_id'] = intval($apppageRectplAreaId);
                        $panelAreaDatas[$key]['pagetpl_id']             = intval($pageId);
                        $panelAreaDatas[$key]['paneltpl_id']            = intval($paneltplId);
                        $panelAreaDatas[$key]['area']                   = $area;
                        $panelAreaDatas[$key]['title']                  = $resoureData->title;
                        $panelAreaDatas[$key]['subtitle']               = $resoureData->subtitle;
                        if (in_array($data->name, ['reclist0', 'collist'])) {
                            $panelAreaDatas[$key]['insert_mode'] = 2;
                        } else {
                            $panelAreaDatas[$key]['insert_mode'] = 1;
                        }
                        // 数据类型
                        $panelAreaDatas[$key]['data_id'] = $dataType;
                        $panelAreaDatas[$key]['range']   = 0;
                        $panelAreaDatas[$key]['tpl_id']  = 0;
                        // 数据ID
                        $panelAreaDatas[$key]['resource_data_id'] = $dataid;
                        $panelAreaDatas[$key]['img']              = null;
                        $panelAreaDatas[$key]['order']            = 0;
                        $panelAreaDatas[$key]['created_at']       = date('Y-m-d H:i:s', time());
                    }
                }
            }
            DB::table('apppage_rectpl_datas')->insert($panelAreaDatas);
            DB::commit();
            return response()->json(['content' => '添加成功！', 'status' => true]);
        } catch (Exception $e) {
            DB::rollback();
            dd($e->getMessage());
        }

    }

    /**
     * 判断推荐此数据是否已存在
     * @param  [type]  $columnrecId           [description]
     * @param  [type]  $columnRecommendDataId [description]
     * @return boolean                        [description]
     */
    public function isExistAppAreaData($pagetplId, $paneltplId, $area, $dataId, $resourceDataId)
    {
        $flag               = true;
        $apppageRecTplDatas = DB::table('apppage_rectpl_datas')
            ->whereNull('deleted_at')
            ->where([
                'pagetpl_id'       => $pagetplId,
                'paneltpl_id'      => $paneltplId,
                'area'             => $area,
                'data_id'          => $dataId,
                'resource_data_id' => $resourceDataId,
            ])
            ->first();
        if (!empty($apppageRecTplDatas)) {
            $flag = false;
        }
        return $flag;
    }
}
